package net.getbang.common.exception;

import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import net.getbang.common.utils.Result;

/**
 * 异常处理器
 * 
 */
@ControllerAdvice
public class GetBangExceptionHandler {
	private Logger logger = LoggerFactory.getLogger(getClass());

	/**
	 * 自定义异常
	 */
	@ExceptionHandler(GetBangException.class)
	@ResponseBody
	public Result handleBDException(GetBangException e) {
		Result r = new Result();
		r.put("code", e.getCode());
		r.put("msg", e.getMessage());

		return r;
	}


	@ExceptionHandler(AuthorizationException.class)
	public String handleAuthorizationException(AuthorizationException e) {
		logger.error(e.getMessage(), e);
		return "error/403";
	}

	@ExceptionHandler(Exception.class)
	public String handleException(Exception e) {
		logger.error(e.getMessage(), e);
		return "error/500";
	}
}
